// handler/handler.go - 处理器层
package handler

import (
	"encoding/json"
	"net/http"
	"spam4lixiang/service"
)

// 获取参数处理器
func GetParamHandler(w http.ResponseWriter, r *http.Request) {
	// 获取请求参数
	model := r.URL.Query().Get("carModel")
	if model == "" {
		http.Error(w, "carModel parameter is required", http.StatusBadRequest)
		return
	}

	// 获取配置数据
	cfg, exists := service.GetConfig(model)
	if !exists {
		http.Error(w, "Model not found", http.StatusNotFound)
		return
	}

	// 返回 JSON 响应
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(cfg)
}
